App({
  onLaunch: function() {
    // 登录
    wx.login({
      success: res => {
        wx.request({
          url: "https://api.weixin.qq.com/sns/jscode2session?appid=wx290976b400142883&secret=d2d75977c7ad0132155bd70be12245fc&js_code=" + res.code + "&grant_type=authorization_code",
          success: res => {
            console.info(res)
            if (res.statusCode == 200) {
              this.globalData.request_common_para.openid = res.data.openid

              /**根据openid查詢user對象 */
              if (this.globalData.request_common_para.openid) {
                wx.request({
                  url: "https://mcc.mtmche.cn/datalake/v1/userInfo?openId=" + this.globalData.request_common_para.openid,

                  method: "GET",
                  success: res => {
                    console.info(" userinfo get success:" + JSON.stringify(res))
                    if (res.statusCode == 200 && res.data && res.data.length > 0) {
                      this.globalData.request_common_para.userInfoId = res.data[0].userInfoId
                      this.globalData.request_common_para.customer_name = res.data[0].customer_name
					  this.globalData.request_common_para.nickName = res.data[0].customer_name
                    }
                  },
                  fail: function(res) {
                    console.info(" userinfo get fail:" + res)
                  }

                })
              } else {
                console.info("=========================");
              }



            }
          }
        })
      }
    })


    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              console.info("wx.login" + res.userInfo.nickName);
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo


              this.globalData.request_common_para.nickName = res.userInfo.nickName



              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })

    wx.getSystemInfo({
      success: res => {
        this.globalData.request_common_para.brand = res.brand
        this.globalData.request_common_para.model = res.model
        this.globalData.request_common_para.version = res.version
        this.globalData.request_common_para.system = res.system
        this.globalData.request_common_para.platform = res.platform
      }
    })



  },
  globalData: {
    userInfo: null,
    request_common_para: {},
    custSourceListData: [{
      name: "二手车之家",
      value: "二手车之家"
    }, {
      name: "朋友介绍",
      value: "朋友介绍"
    }, {
      name: "自己到店",
      value: "自己到店"
    }, {
      name: "保卖车",
      value: "保卖车"
    }, {
      name: "逃车",
      value: "逃车"
    }, {
      name: "其他",
      value: "其他"
    }],
    custStatuListData: [{
      name: "已付定金",
      value: "已付定金"
    }, {
      name: "非常强烈",
      value: "非常强烈"
    }, {
      name: "强烈",
      value: "强烈"
    }, {
      name: "一般",
      value: "一般"
    }, {
      name: "已成交",
      value: "已成交"
    }, {
      name: "战败",
      value: "战败"
    }],
    yearListData: [{
      name: "0-1年",
      value: "0-1年"
    }, {
      name: "1-3年",
      value: "1-3年"
    }, {
      name: "3-5年",
      value: "3-5年"
    }, {
      name: "5-8年",
      value: "5-8年"
    }, {
      name: "8-10年",
      value: "8-10年"
    }, {
      name: "10年以上",
      value: "10年以上"
    }, {
      name: "不限",
      value: "不限",
      checked: true
    }],
    mileageListData: [{
      name: "0-1万公里",
      value: "0-1万公里"
    }, {
      name: "1-3万公里",
      value: "1-3万公里"
    }, {
      name: "3-5万公里",
      value: "3-5万公里"
    }, {
      name: "5-10万公里",
      value: "5-10万公里"
    }, {
      name: "10万公里",
      value: "10万公里"
    }, {
      name: "不限",
      value: "不限",
      checked: true
    }],
    colorListData: [{
      name: "黑",
      value: "黑"
    }, {
      name: "白",
      value: "白"
    }, {
      name: "银",
      value: "银"
    }, {
      name: "灰",
      value: "灰"
    }, {
      name: "红",
      value: "红"
    }, {
      name: "蓝",
      value: "蓝"
    }, {
      name: "绿",
      value: "绿"
    }, {
      name: "黄",
      value: "黄"
    }, {
      name: "金",
      value: "金"
    }, {
      name: "棕",
      value: "棕"
    }, {
      name: "其他",
      value: "其他"
    }],
    menuListData: [{
      "menu_id": "1",
      "menu_name": "客户需求",
      "menu_url": "/page/cust/custInfoList"
    }, {
      "menu_id": "2",
      "menu_name": "需求审核",
      "menu_url": "/page/cust/custInfoAuditing"
    }, {
      "menu_id": "3",
      "menu_name": "需求汇总",
      "menu_url": "/page/cust/custInfoStatistics"
    }, {
      "menu_id": "4",
      "menu_name": "客户信息录入",
      "menu_url": "/page/cust/saveCust"
    }],
    cityListData: [{
      cityCode: "sh",
      cityName: "上海"
    }, {
      cityCode: "bj",
      cityName: "北京"
    }]
  },
  toast1Tap: function() {
    wx.showToast({
      title: "成功"
    })
  },
  toast3Tap: function() {
    wx.showToast({
      title: "loading",
      icon: "loading",
      duration: 2000
    })
  },
  noTitlemodalTap: function(e) {
    wx.showModal({
      content: e,
      confirmText: "确定",
      cancelText: "取消"
    })
  }
})